/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.lockfree;

import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 *
 * @author vlad
 */
public class PowerGenerator {
    private AtomicReference<BigInteger> stored =
            new AtomicReference<>(BigInteger.ONE);
    
    public BigInteger next() {
        BigInteger current = null;
        while(current == null) {
            current = stored.getAndSet(null);
        }
        stored.set(current.multiply(BigInteger.valueOf(2)));
        return current;
    }
}
